/*********************************************************************************
Name:  testVisitorLeadPage()
Copyright © 2012  Lodha Group
======================================================
======================================================
Purpose:
-------
test class for visitor lead page controller
======================================================
======================================================
History
-------
VERSION    AUTHOR                DATE             DETAIL              
1.0 -   CG Dev Team          22/03/2012      INITIAL DEVELOPMENT  
*********************************************************************************/ 
@isTest
private class testVisitorLeadPage
{
     public static testMethod void testLeadClasses() 
     {
                
                User u = [select id from user where Profile.name = 'System Administrator' and isActive = true limit 1];
                system.runas(u){

                Id recType = [Select r.SobjectType, r.Name, r.Id From RecordType r where r.SobjectType = 'VisitorFormSettings__c' and r.Name = 'Lead'].Id;
                Project_name__c project = new Project_name__c();
                project.Name = 'testProject';
                project.project_type__c = 'Casa';
                project.record_type__c  = 'Residential';
                insert project;
                
                VisitorFormSettings__c vfSetting = new VisitorFormSettings__c();
                vfSetting.User__c = u.Id;
                vfSetting.Project_Name__c = project.Id;
                vfSetting.RecordTypeId = recType;
                vfSetting.Default__c = true;
                vfSetting.LeadSource__c = 'Corporate Tie-Up; Newspaper; Hoarding; Channel Partner; Web; Emailer; Others';
                insert vfSetting;

                List<VisitorFormSettings__c> vfSettingList = [select RecordType.Name,id,Name,AccountCSS__c,isFiorenzaTemplate__c, isWorldTowersTemplate__c,ResidenceType__c ,Indulgences__c ,SourceHeader__c ,BudgetTitle__c ,WorkInfo__c ,ContactInfo__c ,OpportunityCSS__c,ThankYouCSS__c,LeadCSS__c,User__c,LeadSource__c,Personal_Details__c,Project_name__c,Default__c,CSS_URL__c from VisitorFormSettings__c where User__c =:UserInfo.getUserId() and RecordType.Name = 'Lead' ];                
                system.debug(vfSetting+'________'+vfSettingList);


                Lead l = new Lead();                   
                l.LastName = 'test';
                l.Mobile__c = '9876543210';
                l.LeadSource = 'website';
                l.Type_of_Accomodation__c = '1 bhk;2bhk';
                l.Project_Name__c = project.Id;
                insert l;
                ApexPages.StandardController controller1 = new ApexPages.StandardController(l);  
                String page1 = '/apex/visitorleadpage' + '?id=' + l.Id ;             
                PageReference pageRef1 = new PageReference(page1);        
                Test.setCurrentPage(pageRef1);
                ApexPages.StandardController controller2 =  new ApexPages.StandardController(l);        
                VisitorLeadPageController ctrl2 =  new VisitorLeadPageController(controller2);
                ctrl2.getItems();
                ctrl2.getLeadSourceList();
                ctrl2.leadsource = 'Website';
                ctrl2.submitLead(); 
                
                //New Lead
                ApexPages.StandardController controller3 = new ApexPages.StandardController(l);  
                String page3 = '/apex/visitorleadpage'; 
                PageReference pageRef3 = new PageReference(page3);        
                Test.setCurrentPage(pageRef3 );
                ApexPages.StandardController controller4 =  new ApexPages.StandardController(l);        
                VisitorLeadPageController ctrl4 =  new VisitorLeadPageController(controller4);
                ctrl4.getItems();
                ctrl4.getLeadSourceList();
                ctrl2.leadsource = 'Website';
                ctrl4.submitLead();                 
                }
     }
}